package cn.script.game.opt;

import cn.script.call_api.AfterApi;
import cn.script.call_api.BeforeApi;
import cn.script.call_api.MoveOpt;
import cn.script.call_api.OptApi;
import cn.script.domain.Skill;
import cn.script.game.GameInfo;
import cn.script.game.GameOpt;

import java.util.List;

/**
 * 副本操作
 *
 * @author 周永波
 */
public class DupOpt implements OptApi {

    private GameInfo gi;

    private GameOpt go;

    private Attack attack;

    private BeforeApi before;

    private AfterApi after;

    private MoveLocation moveLocation;

    public DupOpt(GameOpt go, String cityName, String attName) {
        this.go = go;
        this.gi = go.gi();
        if (cityName != null) {
            this.moveLocation = new MoveLocation(gi, cityName);
        }
        if (attName != null) {
            this.attack = new Attack(go, attName);
        }
    }

    public DupOpt beFore(BeforeApi beforeApi) {
        this.before = beforeApi;
        return this;
    }

    public DupOpt after(AfterApi afterApi) {
        this.after = afterApi;
        return this;
    }


    public Attack getAttack() {
        return this.attack;
    }

    public DupOpt m_winPoint(int x, int y) {
        this.moveLocation.winPoint(x, y);
        return this;
    }

    public DupOpt m_gamePoint(int x, int y) {
        this.moveLocation.gamePoint(x, y);
        return this;
    }

    public DupOpt m_rPoint(int rx, int ry) {
        this.moveLocation.rPoint(rx, ry);
        return this;
    }

    public DupOpt m_num(int num) {
        this.moveLocation.num(num);
        return this;
    }

    public DupOpt moveOpt(MoveOpt moveOpt) {
        this.moveLocation.moveOpt(moveOpt);
        return this;
    }

    public DupOpt moveAfter(AfterApi afterApi) {
        this.moveLocation.after(afterApi);
        return this;
    }


    public DupOpt a_range(int x, int y, int x1, int y1) {
        this.attack.range(x, y, x1, y1);
        return this;
    }


    public DupOpt a_endNum(int endNum) {
        this.attack.endNum(endNum);
        return this;
    }

    public DupOpt a_skills(Skill... skillArr) {
        this.attack.skills(skillArr);
        return this;
    }

    public DupOpt a_skills(List<Skill> skills) {
        this.attack.skills(skills);
        return this;
    }

    public DupOpt a_timeOut(int timeOut) {
        this.attack.timeOut(timeOut);
        return this;
    }


    @Override
    public int opt() {
        if (this.before != null) {
            this.before.opt();
        }
        if (this.moveLocation != null) {
            int m_ret = this.moveLocation.opt();
            if (m_ret == 0) {
                return 0;
            }
        }

        if (this.attack != null) {
            int a_ret = this.attack.opt();
            if (a_ret == 0) {
                return 0;
            }
        }
        if (this.after != null) {
            this.after.opt();
        }
        return 1;
    }
}
